home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Path: cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Subject: Re: Access carry flag from C
- Message-ID: <DnB4xF.5rE@cwi.nl>
- Sender: news@cwi.nl (The Daily Dross)
- Nntp-Posting-Host: chrysant.cwi.nl
- Organization: CWI, Amsterdam
- References: <TANMOY.96Feb21081640@qcd.lanl.gov> <312D8414.167E@bazis.nl> <4glk5t$avt@sun001.spd.dsccc.com>
- Date: Sun, 25 Feb 1996 01:17:39 GMT
-
- Franz Korntner quotes rationale 2.2.4.2.1 and Mike McCarty quotes standard
- 5.2.4.2.1 (and I repeat the relevant part of that):
- > Their implementation-defined values shall be
- > equal or greater in magnitude (absolute value) to those shown, with
- > the same sign.
-
- Both conlcude that the actual arithmetic can have larger limits than
- those documented in limits.h. But this does in no way state that the
- limits given in limits.h can be less than the actually implemented limits.
- It only states that the actually implemented limits can be larger than
- the limits given (as an example) in the standard. By words in other parts
- of the standard (as quoted by Tanmoy) it is clear that the limits as
- documented in limits.h must be the actual limits.
-
- However, exceeding INT_MAX in signed arithmetic results in undefined
- behaviour (and may very well result in a representation that would be
- larger than the actual value). For instance on a Cray the C compiler
- has two modes of compilation. The first is with "fast integer arithmetic"
- and if done in that mode INT_MAX is defined as 2^46-1, adding 1 to that
- value will result in an internal representation of 2^47. But using that
- value in some multiplication will handle it as if 0 was used. Allowed
- because the result is undefined and anything can happen on overflow of
- signed ints. On the other hand the behaviour of unsigned int with respect
- to UINT_MAX is well defined. Adding 1 to UINT_MAX results in 0 (per the
- standard). (And on that same Cray UINT_MAX is defined as 2^64-1
- regardless of the mode of compilation used.)
-
- So, INT_MAX does not give much guarantee about the actual arithmetic
- used; UINT_MAX does. But only because the result of exceeding INT_MAX
- is undefined behaviour.
-
- [And for Dan Bernstein: the Cray does not have a carry flag either.]
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
-